﻿using System.Linq;
using Interfaces.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation;

namespace Framework.Validation
{
    public static class ValidationResultsConverter
    {
        public static IValidationResult Convert(ValidationResults results,object target)
        {
            var rules = from rule in results select Convert(rule);
            return new GenericValidationResult(target, results.IsValid, rules);
        }

        private static BrokenRule Convert(ValidationResult result)
        {
            return new BrokenRule(result.Key, result.Message, result.Tag, result.Target);
        }
    }
}
